﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinkCard.Model;

namespace LinkCard.Dao
{
    public class PayLogDao
    {
        public int Add(object obj)
        {
            var rs = 0;
            try
            {
                var db = new TopLinkEntities();
                var objAdd = (PayLog)obj;
                db.AddToPayLog(objAdd);
                rs = db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return rs;
        }
        public int Delete(object obj)
        {
            var rs = 0;
            try
            {
                var db = new TopLinkEntities();
                var objDel = (PayLog)obj;
                var id = objDel.PayID;
                var oldObj = db.PayLog.FirstOrDefault(t => t.PayID == id);
                if (oldObj != null)
                {
                    db.DeleteObject(oldObj);
                    rs = db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return rs;
        }

        public PayLog GetById(long id)
        {
            var ct = new PayLog();
            try
            {
                var db = new TopLinkEntities();
                ct = db.PayLog.FirstOrDefault(t => t.PayID == id);
            }
            catch (Exception)
            {
                throw;
            }
            return ct;
        }

        public List<PayLog> GetAll()
        {
            var lst = new List<PayLog>();
            try
            {
                var db = new TopLinkEntities();
                lst = db.PayLog.ToList();
            }
            catch (Exception)
            {
                throw;
            }
            return lst;
        }
    }
}
